/**
 * 素材上传 multer 封装
 * @authors 杨兴洲（of2502）
 * @date    2017/3/17 11:43
 * @version 1.0
 */

import * as multer from "multer";
import CONFIG from "../config";

const storage: multer.StorageEngine = multer.diskStorage({
    destination(req, file, cb){
        cb(null, CONFIG.UPLOAD_DIR);
    },
    filename(req, file, cb){
        const fileFormat = (file.originalname).split(".");
        const fileType = fileFormat[fileFormat.length - 1];
        cb(null, file.fieldname + '-' + Date.now() + "." + fileType);
    }
});

// const storage = multer.memoryStorage();
const upload: multer.Instance = multer({storage});

export default upload;
